<?php
set_time_limit(0);
$this->LoadHelper('OrderHelper');
$OrderHelper = new OrderHelper();

$this->LoadHelper('FtpUploadHelper');
$FtpUploadHelper = new FtpUploadHelper();

$this->LoadHelper('AttachHelper');
$AttachHelper = new AttachHelper($this->UserConfig, 'task');

$model = $this->LoadModel('Public');
$temp_att = $model->getList('attachment', '*', array('`delete_status` = ?' => 1));
if(!empty($temp_att)) foreach ($temp_att as $k => $v){
    @unlink(WEB_PATH . $v['url']);
    $exp_file = explode('/', $v['url']);
    $exp_file_count = count($exp_file);
    $filename = end($exp_file);
    $thumb_img = '';
    $directory = '';
    foreach($exp_file as $k => $v){
        if($k == $exp_file_count - 1){
            $thumb_img = $thumb_img . 's_' . $filename;
        }else{
            $thumb_img .= $v.'/';
            $directory .= $v.'/';
        }
    }
    @unlink(WEB_PATH . $thumb_img);
    if($v['is_ftp'] == 1){
        $FtpUploadHelper = new FtpUploadHelper();
        $FtpUploadHelper->Set(0);
        //$d = $FtpUploadHelper->FtpUpload->FtpChdir(dirname($directory));
        $FtpUploadHelper->FtpUpload->FtpChdir($directory);
        $FtpUploadHelper->FtpUpload->FtpDelete($filename);
        $FtpUploadHelper->FtpUpload->FtpClose();
    }
    $model->update('attachment', array('delete_status' => 2), array('at_id' => $v['at_id']));
}
echo '<p>清理成功</p>';